/**
 * @see https://umijs.org/zh-CN/plugins/plugin-access
 * */
export default function access(initialState: { currentUser?: LoginResponse.UserInfo | undefined }) {
  const { currentUser } = initialState || {};
  window.console.log(currentUser?.access)
  // return {
  //   admin: currentUser && currentUser?.access === 'admin',
  // };
  /**
   * 权限校验
   * @param User 用户信息
   * @param access 
   */
   const checkAuth = (User: LoginResponse.UserInfo | undefined, scopes: any) => {
    // 超级管理员
    if(User?.is_admin){
      return true
    }
    return User && !(User.access.indexOf(scopes) === -1)
  }
  
  return {
    admin: checkAuth(currentUser, "admin"),
    admin_user: checkAuth(currentUser, "admin_user"),
    admin_role: checkAuth(currentUser, "admin_role"),
  };
}
